home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Source / Property Editors / dsattra.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  5KB  |  168 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {       Dataset Designer Associate Attributes Dialog    }
  6. {                                                       }
  7. {       Copyright (c) 1997,99 Inprise Corporation       }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit DSAttrA;
  12.  
  13. interface
  14.  
  15. uses Windows, Messages, SysUtils, Classes, Graphics, Forms, Controls,
  16.   StdCtrls, Buttons, ExtCtrls, DRIntf, LibHelp;
  17.  
  18. type
  19.   TAssociateAttributes = class(TForm)
  20.     OKBtn: TButton;
  21.     CancelBtn: TButton;
  22.     HelpBtn: TButton;
  23.     GroupBox1: TGroupBox;
  24.     AttributeNamesList: TListBox;
  25.     Edit: TEdit;
  26.     procedure OKBtnClick(Sender: TObject);
  27.     procedure CancelBtnClick(Sender: TObject);
  28.     procedure HelpBtnClick(Sender: TObject);
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure EditChange(Sender: TObject);
  31.     procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  32.     procedure ListBoxClick(Sender: TObject);
  33.     procedure ListBoxDblClick(Sender: TObject);
  34.   private
  35.     procedure AddToList(const Value: string);
  36.   public
  37.     function Execute(var AttrID: TAttrID; var Continue: Boolean): Boolean;
  38.   end;
  39.  
  40. function GetAssociateAttributes(var AttrID: TAttrID; var Continue: Boolean): Boolean;
  41.  
  42. implementation
  43.  
  44. uses DsnDBCst;
  45.  
  46. {$R *.DFM}
  47.  
  48. function GetAssociateAttributes(var AttrID: TAttrID; var Continue: Boolean): Boolean;
  49. var
  50.   AssociateAttributes: TAssociateAttributes;
  51. begin
  52.   AssociateAttributes := TAssociateAttributes.Create(Application);
  53.   try
  54.     Result := AssociateAttributes.Execute(AttrID, Continue);
  55.   finally
  56.     AssociateAttributes.Free;
  57.   end;
  58. end;
  59.  
  60. procedure TAssociateAttributes.OKBtnClick(Sender: TObject);
  61. begin
  62.   ModalResult := mrOK;
  63. end;
  64.  
  65. procedure TAssociateAttributes.CancelBtnClick(Sender: TObject);
  66. begin
  67.   ModalResult := mrCancel;
  68. end;
  69.  
  70. procedure TAssociateAttributes.AddToList(const Value: string);
  71. begin
  72.   AttributeNamesList.Items.Add(Value);
  73. end;
  74.  
  75. procedure TAssociateAttributes.FormCreate(Sender: TObject);
  76. begin
  77.   GetAttrNames(AddToList);
  78.   HelpContext := hcDAssociateAttributes;
  79.   if AttributeNamesList.Items.Count > 0 then
  80.     Edit.Text := AttributeNamesList.Items[0] else
  81.     raise Exception.CreateRes(@SDSNoAttrs);
  82. end;
  83.  
  84. procedure TAssociateAttributes.EditChange(Sender: TObject);
  85. var
  86.   I, L, C, Count: Integer;
  87.   S: string;
  88. begin
  89.   Count := AttributeNamesList.Items.Count;
  90.   if Count > 0 then
  91.   begin
  92.     S := Edit.Text;
  93.     L := Length(S);
  94.     C := -1;
  95.     I := 0;
  96.     if L > 0 then
  97.     begin
  98.       while I < Count do
  99.       begin
  100.         C := AnsiCompareText(Copy(AttributeNamesList.Items[I], 1, L), S);
  101.         if C >= 0 then Break;
  102.         Inc(I);
  103.       end;
  104.     end;
  105.     if C = 0 then
  106.     begin
  107.       if AttributeNamesList.ItemIndex <> I then
  108.       begin
  109.         AttributeNamesList.ItemIndex := -1;
  110.         AttributeNamesList.TopIndex := I;
  111.         AttributeNamesList.ItemIndex := I;
  112.       end;
  113.       OKBtn.Enabled := True;
  114.     end else
  115.     begin
  116.       AttributeNamesList.ItemIndex := -1;
  117.       if L = 0 then AttributeNamesList.TopIndex := 0;
  118.       OKBtn.Enabled := False;
  119.     end;
  120.   end;
  121. end;
  122.  
  123. procedure TAssociateAttributes.ListBoxClick(Sender: TObject);
  124. begin
  125.   if AttributeNamesList.ItemIndex >= 0 then
  126.   begin
  127.     Edit.Text := AttributeNamesList.Items[AttributeNamesList.ItemIndex];
  128.     Edit.SelectAll;
  129.   end;
  130. end;
  131.  
  132. procedure TAssociateAttributes.ListBoxDblClick(Sender: TObject);
  133. begin
  134.   if OKBtn.Enabled then OKBtn.Click;
  135. end;
  136.  
  137. procedure TAssociateAttributes.EditKeyDown(Sender: TObject; var Key: Word;
  138.   Shift: TShiftState);
  139. begin
  140.   if not (ssAlt in Shift) and (Key in [VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT]) then
  141.   begin
  142.     SendMessage(AttributeNamesList.Handle, WM_KEYDOWN, Key, 0);
  143.     Key := 0;
  144.   end;
  145. end;
  146.  
  147. function TAssociateAttributes.Execute(var AttrID: TAttrID; var Continue: Boolean): Boolean;
  148. var
  149.   ModalResult: Integer;
  150. begin
  151.   if not IsNullID(AttrID) then Edit.Text := GetAttrName(AttrID);
  152.   Edit.SelectAll;
  153.   AttributeNamesList.ItemIndex := AttributeNamesList.Items.IndexOf(Edit.Text);
  154.   OKBtn.Enabled := AttributeNamesList.ItemIndex >= 0;
  155.   ModalResult := ShowModal;
  156.   Result := ModalResult = mrOk;
  157.   Continue := ModalREsult <> mrCancel;
  158.   if Result and (AttributeNamesList.ItemIndex >= 0) then
  159.     AttrID := FindAttrID(AttributeNamesList.Items[AttributeNamesList.ItemIndex]);
  160. end;
  161.  
  162. procedure TAssociateAttributes.HelpBtnClick(Sender: TObject);
  163. begin
  164.   Application.HelpContext(HelpContext);
  165. end;
  166.  
  167. end.
  168.